﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////

#include "CmdGRepModuleEntry.h"
#include "IControl.h"
#include "IRibbonGroup.h"
#include "IGroupHandler.h"
#include "GcmpCommandState.h"
#include "IComboBoxDefinition.h"
#include "ICommandButtonDefinition.h"
#include "ICheckBoxGroupDefinition.h"

#include "UiBuilder.h"
#include "GRepCommandIds.h"
#include "CommandRegister.h"
#include "SampleUIUtils.h"
#include "GRepProbe/GrepProbeDlg.h"
#include "GRepProbe/ObjectBrowser.h"
#include "ICommandButtonMenuDefinition.h"
#include "ICommandMenuItemDefinition.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 


/// 本文件是界面实现的辅助类，不包含GDMP API的演示内容

using namespace Sample;
using namespace gcmp;

#pragma region 各种Ribbon控件的状态控制
// 整个捕捉模块Ribbon可见性控制
class GrepGroupHandler : public IGroupHandler
{

public:
    virtual bool IsVisible() const override
    {
        return GcmpCommandState::IsInDocumentEnvironment();
    }
};
#pragma endregion 各种Ribbon控件的状态控制

#pragma  region CmdGRepHelp
REGISTER_COMMAND(CmdGRepHelp)

CmdGRepHelp::CmdGRepHelp() : CommandBase(ID_CMD_GREP_HELP) {}
CmdGRepHelp::~CmdGRepHelp() {}

gcmp::OwnerPtr<gcmp::IAction> CmdGRepHelp::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    ShellExecute(NULL, L"open", L"https://developer.glodon.com/docs/gdmp/24.0.0305.0/cppdev/ayz5vl9i", NULL, NULL, SW_SHOWNORMAL);
    return nullptr;
}

bool CmdGRepHelp::IsEnabled() const
{
    return GcmpCommandState::IsInDocumentEnvironment();
}

bool CmdGRepHelp::IsVisible() const
{
    return GcmpCommandState::IsInDocumentEnvironment();
}
#pragma endregion

#pragma region CmdGRepModuleEntry

REGISTER_COMMAND(CmdGRepModuleEntry)

CmdGRepModuleEntry::CmdGRepModuleEntry()
    : CommandBase(ID_CMD_GREP_ENTRY)
{}

CmdGRepModuleEntry::~CmdGRepModuleEntry(){}

bool CmdGRepModuleEntry::IsEnabled() const
{
    return GcmpCommandState::IsInDocumentEnvironment();
}

bool CmdGRepModuleEntry::IsVisible() const
{
    return GcmpCommandState::IsInDocumentEnvironment();
}

IRibbonGroup* Sample::CmdGRepModuleEntry::GetRibbonGroup()
{
    ModuleUIUtils* pModuleUIUtils = ModuleUIUtils::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pModuleUIUtils, L"pModuleUIUtils为空",L"GDMP",L"2024-03-30");
    return SampleUIUtils::FindGroup(ID_PAGE_MODULE, ID_GROUP_MODULE_PICK_CONTEXT);
}

const PreviewStyle Sample::CmdGRepModuleEntry::GetPreviewStyle()
{
    static PreviewStyle s_previewStyle = PreviewStyle::PreHighLight;

    IRibbonGroup* pRibbonGroup = GetRibbonGroup();

    if (!pRibbonGroup) return s_previewStyle;
    IControl* pControl = pRibbonGroup->GetControl(ID_COMBOBOX_GREP_PREVIEW_STYLE);
    if (!pControl) return s_previewStyle;
    IComboBoxDefinition* pComboDefinition = dynamic_cast<IComboBoxDefinition*>(pControl->GetControlDefinition());
    DBG_WARN_AND_RETURN_UNLESS(pComboDefinition, PreviewStyle::PreHighLight, L"pComboDefinition为空",L"GDMP",L"2024-03-30");
    Any userData = pComboDefinition->GetCurrentData();
    s_previewStyle = userData.cast<PreviewStyle>();
    return s_previewStyle;
}

const Sample::AddNodeStyle Sample::CmdGRepModuleEntry::GetAddNodeStyle()
{
    IRibbonGroup* pRibbonGroup = GetRibbonGroup();
    if (!pRibbonGroup) return AddNodeStyle::Directly;
    IControl* pControl = pRibbonGroup->GetControl(ID_COMBOBOX_GREP_ADDNODE_STYLE);
    DBG_WARN_AND_RETURN_UNLESS(pControl, AddNodeStyle::Directly, L"pControl为空",L"GDMP",L"2024-03-30");
    IComboBoxDefinition* pComboDefinition = dynamic_cast<IComboBoxDefinition*>(pControl->GetControlDefinition());
    DBG_WARN_AND_RETURN_UNLESS(pComboDefinition, AddNodeStyle::Directly, L"pComboDefinition为空",L"GDMP",L"2024-03-30");
    Any userData = pComboDefinition->GetCurrentData();
    return userData.cast<AddNodeStyle>();
}

const ConvertStyle Sample::CmdGRepModuleEntry::GetConvertStyle()
{
    IRibbonGroup* pRibbonGroup = GetRibbonGroup();
    if (!pRibbonGroup) return ConvertStyle::DirectShape;
    IControl* pControl = pRibbonGroup->GetControl(ID_COMBOBOX_GREP_CONVERT_DS_OR_PGE);
    DBG_WARN_AND_RETURN_UNLESS(pControl, ConvertStyle::DirectShape, L"pControl为空",L"GDMP",L"2024-03-30");
    IComboBoxDefinition* pComboDefinition = dynamic_cast<IComboBoxDefinition*>(pControl->GetControlDefinition());
    DBG_WARN_AND_RETURN_UNLESS(pComboDefinition, ConvertStyle::DirectShape, L"pComboDefinition为空",L"GDMP",L"2024-03-30");
    Any userData = pComboDefinition->GetCurrentData();
    return userData.cast<ConvertStyle>();
}

OwnerPtr<IAction> CmdGRepModuleEntry::ExecuteCommand(const CommandParameters& cmdParams)
{
    ModuleUIUtils::Get()->RemoveModuleUI();
    UiBuilder::CleanContextUI();

    if (GetRibbonGroup())
    {
        return nullptr;
    }

    ObjectBrowser::DisplayPanel();
    GrepProbeDlg* grepProbeDlg = GrepProbeDlg::GetOrCreate();
    grepProbeDlg->ShowDock();

    std::wstring groupName = L"图形节点模块示例";

    OwnerPtr<IRibbonGroup> opGrepGroup = IRibbonGroup::Create(ID_GROUP_MODULE_PICK_CONTEXT, GBMP_TR(groupName));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGrepGroup, L"opGrepGroup为空",L"GDMP",L"2024-03-30");
    opGrepGroup->SetGroupHandler(NEW_AS_OWNER_PTR(GrepGroupHandler));

    OwnerPtr<IComboBoxDefinition> opComboBoxPreviewStyleDefinition =
        IComboBoxDefinition::Create(ID_COMBOBOX_GREP_PREVIEW_STYLE, L"探针节点高亮方式:");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opComboBoxPreviewStyleDefinition, L"opComboBoxPreviewStyleDefinition为空",L"GDMP",L"2024-03-30");
    opComboBoxPreviewStyleDefinition->AddItem(L"PreHighLight", PreviewStyle::PreHighLight);
    opComboBoxPreviewStyleDefinition->AddItem(L"HighLight", PreviewStyle::HighLight);
    opGrepGroup->AddComboBox(TransferOwnership(opComboBoxPreviewStyleDefinition));

    OwnerPtr<IComboBoxDefinition> opComboBoxAddNodeStyleDefinition =
        IComboBoxDefinition::Create(ID_COMBOBOX_GREP_ADDNODE_STYLE, L"添加GNode方式:");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opComboBoxAddNodeStyleDefinition, L"opComboBoxAddNodeStyleDefinition为空",L"GDMP",L"2024-03-30");
    opComboBoxAddNodeStyleDefinition->AddItem(L"直接添加", AddNodeStyle::Directly);
    opComboBoxAddNodeStyleDefinition->AddItem(L"组合为IGraphicsNodeGroup", AddNodeStyle::AsGGroup);
    opComboBoxAddNodeStyleDefinition->AddItem(L"添加为IGraphicsElementReference", AddNodeStyle::GraphicsElementReference);
    opGrepGroup->AddComboBox(TransferOwnership(opComboBoxAddNodeStyleDefinition));
    
    OwnerPtr<IComboBoxDefinition> opComboBoxConvertDS_GPEDefinition =
        IComboBoxDefinition::Create(ID_COMBOBOX_GREP_CONVERT_DS_OR_PGE, L"复制GRep方式:");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opComboBoxConvertDS_GPEDefinition, L"opComboBoxConvertDS_GPEDefinition为空",L"GDMP",L"2024-03-30");
    opComboBoxConvertDS_GPEDefinition->AddItem(L"复制为IDirectShape", ConvertStyle::DirectShape);
    opComboBoxConvertDS_GPEDefinition->AddItem(L"复制为IPureGraphicsElementShape", ConvertStyle::PureGraphicsElementShape);
    opGrepGroup->AddComboBox(TransferOwnership(opComboBoxConvertDS_GPEDefinition));

    OwnerPtr<ICommandButtonDefinition> opGrepProbeButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_PROBE, GBMP_TR(L"模型图形表达探针"),
            GBMP_TR(L"读取选择图元的模型图形表达。如果选择图元为IDirectShape或IPureGraphicsElement，那么可以修改图元的模型图形表达；其他类型图元可以用“复制GRep为可编辑”生成可修改的IDirectShape或IPureGraphicsElement"),
            ID_CMD_GREP_PROBE, L":/images/Module/Grep/grep_tree.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGrepProbeButtonDefinition, L"opGrepProbeButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opGrepProbeButtonDefinition));

    OwnerPtr<ICommandButtonDefinition> opViewGrepProbeButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_VIEW_GREP_PROBE, GBMP_TR(L"视图图形表达探针"),
            GBMP_TR(L"读取选择图元的视图图形表达。视图图形表达不可修改，可以用“复制视图GRep为可编辑”生成可修改的IDirectShape或IPureGraphicsElement后，修改生成图元的模型图形表达"),
            ID_CMD_VIEW_GREP_PROBE, L":/images/Module/Grep/viewSpecific.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opViewGrepProbeButtonDefinition, L"opViewGrepProbeButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opViewGrepProbeButtonDefinition));

    /*
    OwnerPtr<ICommandButtonDefinition> opConvertGRepToDSButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_CONVERT_TO_DS, GBMP_TR(L"复制GRep为可编辑"),
            GBMP_TR(L"复制为IDirectShape或IPureGraphicsElement。如果复制为IDirectShape，节点上的显示样式或材质可能会被计算器覆盖而丢失。"),
            ID_CMD_GREP_CONVERT_TO_DS, L":/images/Module/Grep/copyGrep.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opConvertGRepToDSButtonDefinition, L"opConvertGRepToDSButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opConvertGRepToDSButtonDefinition));

    OwnerPtr<ICommandButtonDefinition> opConvertVGRepToDSButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_VIEW_GREP_CONVERT_TO_DS, GBMP_TR(L"复制视图GRep为可编辑"),
            GBMP_TR(L"复制选择图元在当前视图的视图图形表达为IDirectShape或IPureGraphicsElement。如果复制为IDirectShape，节点上的显示样式或材质可能会被计算机覆盖而丢失。"),
            ID_CMD_VIEW_GREP_CONVERT_TO_DS, L":/images/Module/Grep/copyViewGrep.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opConvertVGRepToDSButtonDefinition, L"opConvertVGRepToDSButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opConvertVGRepToDSButtonDefinition));
    */

    OwnerPtr<ICommandButtonMenuDefinition> opConvertGRepButtonMenuDefinition =
        ICommandButtonMenuDefinition::Create(ID_CMD_GREP_CONVERT_TO_DS, ID_CMD_GREP_CONVERT_TO_DS,
            GBMP_TR(L"复制GRep为可编辑"), L":/images/Module/Grep/copyGrep.png",
            GBMP_TR(L"复制为IDirectShape或IPureGraphicsElement。如果复制为IDirectShape，节点上的显示样式或材质可能会被计算器覆盖而丢失。"));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opConvertGRepButtonMenuDefinition, L"opConvertGRepButtonMenuDefinition为空", L"GDMP", L"2024-03-30");
    {
        OwnerPtr<ICommandMenuItemDefinition> opConvertGRepToDSButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_CONVERT_TO_DS, ID_CMD_GREP_CONVERT_TO_DS, GBMP_TR(L"复制GRep为可编辑"),
                GBMP_TR(L"复制为IDirectShape或IPureGraphicsElement。如果复制为IDirectShape，节点上的显示样式或材质可能会被计算器覆盖而丢失。"),
                L":/images/Module/Grep/copyGrep.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opConvertGRepToDSButtonItemDefinition, L"opConvertGRepToDSButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opConvertGRepButtonMenuDefinition->AddItem(TransferOwnership(opConvertGRepToDSButtonItemDefinition));

        OwnerPtr<ICommandMenuItemDefinition> opConvertVGRepToDSButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_VIEW_GREP_CONVERT_TO_DS, ID_CMD_VIEW_GREP_CONVERT_TO_DS, GBMP_TR(L"复制视图GRep为可编辑"),
            GBMP_TR(L"复制选择图元在当前视图的视图图形表达为IDirectShape或IPureGraphicsElement。如果复制为IDirectShape，节点上的显示样式或材质可能会被计算机覆盖而丢失。"),
                L":/images/Module/Grep/copyViewGrep.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opConvertVGRepToDSButtonItemDefinition, L"opConvertVGRepToDSButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opConvertGRepButtonMenuDefinition->AddItem(TransferOwnership(opConvertVGRepToDSButtonItemDefinition));
    }
    opGrepGroup->AddButtonMenu(TransferOwnership(opConvertGRepButtonMenuDefinition));

    OwnerPtr<ICommandButtonDefinition> opAddNodeButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_ADD_NODE, GBMP_TR(L"添加GNode"),
            GBMP_TR(L"将选择图元的GRep添加到模型图形表达探针树中选择的节点位置。运行该命令前，需要在IDirectShape或IPureGraphicsElement上运行“模型图形表达探针”，在探针树上选择一个节点，然后选择一个图元。"),
            ID_CMD_GREP_ADD_NODE, L":/images/Module/Grep/AddNode.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opAddNodeButtonDefinition, L"opAddNodeButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opAddNodeButtonDefinition));

    OwnerPtr<ICommandButtonDefinition> opRemoveNodeButtonDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_REMOVE_NODE, GBMP_TR(L"删除GNode"),
            GBMP_TR(L"将探针树中选择节点位置的IGraphicsNode删除。"),
            ID_CMD_GREP_REMOVE_NODE, L":/images/Module/Grep/RemoveNode.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opRemoveNodeButtonDefinition, L"opRemoveNodeButtonDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opRemoveNodeButtonDefinition));

    OwnerPtr<ICommandButtonDefinition> opGRepCreateHolderDefinition =
        ICommandButtonDefinition::Create(ID_CMD_CREATE_GREP_HOLDER, GBMP_TR(L"创建GRepHolder"),
            GBMP_TR(L"用选择图元的模型GRep创建GRepHolder。GRepHolder图元，类别为BICU_ELEMENT_GREP_HOLDER，用于做几何和显示共享。"),
            ID_CMD_CREATE_GREP_HOLDER, L":/images/Module/Grep/GrepHolder.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGRepCreateHolderDefinition, L"opGRepCreateHolderDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opGRepCreateHolderDefinition));

    OwnerPtr<ICommandButtonDefinition> opGRepUseHolderDefinition =
        ICommandButtonDefinition::Create(ID_CMD_USE_GREP_HOLDER, GBMP_TR(L"使用GRepHolder"),
            GBMP_TR(L"用选择的GRepHolder创建GRepHolderUser。GRepHolderUser图元是GRepHolder的使用者，GRepHolderUser的GRep中只包含GRepHolder创建的IGraphicsElementShapeReference。"),
            ID_CMD_USE_GREP_HOLDER, L":/images/Module/Grep/GrepHolderUser.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGRepUseHolderDefinition, L"opGRepCreateHolderDefinition为空",L"GDMP",L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opGRepUseHolderDefinition));
    
    OwnerPtr<ICommandButtonMenuDefinition> opGNodeIdButtonMenuDefinition =
        ICommandButtonMenuDefinition::Create(ID_CMD_GREP_SHOW_GNODE_ID, ID_CMD_GREP_SHOW_GNODE_ID,
            GBMP_TR(L"显示GNodeId"), L":/images/Module/Grep/gNodeId.png",
            GBMP_TR(L"显示选中图元的GNodeId，包括追溯到历史且与现在不同的GNodeId。Group红色，Edge橄榄绿，Face蓝色，Body紫色，其他不显示。"));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGNodeIdButtonMenuDefinition, L"opGNodeIdButtonMenuDefinition为空", L"GDMP", L"2024-03-30");
    {
        OwnerPtr<ICommandMenuItemDefinition> opSetGNodeIdButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_SET_GNODE_ID, ID_CMD_GREP_SET_GNODE_ID, GBMP_TR(L"简单设置GNodeId"),
                GBMP_TR(L"对选中的IPureGraphicsElement或IDirectShape设置NodeId，设置方式用id递增的简单方式。"), L":/images/Module/Grep/gNodeId.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opSetGNodeIdButtonItemDefinition, L"opSetGNodeIdButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opGNodeIdButtonMenuDefinition->AddItem(TransferOwnership(opSetGNodeIdButtonItemDefinition));

        OwnerPtr<ICommandMenuItemDefinition> opShowGNodeIdButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_SHOW_GNODE_ID, ID_CMD_GREP_SHOW_GNODE_ID, GBMP_TR(L"显示图元GNodeId"),
                GBMP_TR(L"显示选中图元的GNodeId，包括追溯到历史且与现在不同的GNodeId。"), L":/images/Module/Grep/gNodeId.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opShowGNodeIdButtonItemDefinition, L"opShowGNodeIdButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opGNodeIdButtonMenuDefinition->AddItem(TransferOwnership(opShowGNodeIdButtonItemDefinition));

        OwnerPtr<ICommandMenuItemDefinition> opCreateGNodeIdButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_CREATE_GNODE_ID_ELEM, ID_CMD_GREP_CREATE_GNODE_ID_ELEM, GBMP_TR(L"创建GNodeId图元"),
                GBMP_TR(L"用建模运算器的方式创建GNodeId图元，展示节点标识系统，比较不同建模接口在节点标识上的区别。"), L":/images/Module/Grep/gNodeId.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opCreateGNodeIdButtonItemDefinition, L"opCreateGNodeIdButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opGNodeIdButtonMenuDefinition->AddItem(TransferOwnership(opCreateGNodeIdButtonItemDefinition));
    }
    opGrepGroup->AddButtonMenu(TransferOwnership(opGNodeIdButtonMenuDefinition));

    OwnerPtr<ICommandButtonMenuDefinition> opExportButtonMenuDefinition =
        ICommandButtonMenuDefinition::Create(ID_CMD_GREP_EXPORT, ID_CMD_GREP_EXPORT,
            GBMP_TR(L"批量导出GRep"), L":/images/Module/Grep/grep_export.png",
            GBMP_TR(L"批量导出GRep。"));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opExportButtonMenuDefinition, L"opExportButtonMenuDefinition为空", L"GDMP", L"2024-03-30");
    {
        OwnerPtr<ICommandMenuItemDefinition> opExportGRepButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_EXPORT, ID_CMD_GREP_EXPORT, GBMP_TR(L"批量导出GRep"),
                GBMP_TR(L"导出视图中所有可见图元的GRep，每个图元导出为一个JSon文件。"), L":/images/Module/Grep/grep_export.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opExportGRepButtonItemDefinition, L"opExportGRepButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opExportButtonMenuDefinition->AddItem(TransferOwnership(opExportGRepButtonItemDefinition));

        OwnerPtr<ICommandMenuItemDefinition> opImportGRepButtonItemDefinition =
            ICommandMenuItemDefinition::Create(ID_CMD_GREP_IMPORT, ID_CMD_GREP_IMPORT, GBMP_TR(L"批量导入GRep"),
                GBMP_TR(L"将选中文件夹中所有的JSon文件导入为IPureGraphicsElement。"), L":/images/Module/Grep/grep_import.png");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opImportGRepButtonItemDefinition, L"opImportGRepButtonItemDefinition为空", L"GDMP", L"2024-03-30");
        opExportButtonMenuDefinition->AddItem(TransferOwnership(opImportGRepButtonItemDefinition));
    }
    opGrepGroup->AddButtonMenu(TransferOwnership(opExportButtonMenuDefinition));

    OwnerPtr<ICommandButtonDefinition> opGRepCreateModelDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_CREATE_MODEL, GBMP_TR(L"创建测试模型"),
            GBMP_TR(L"创建包含各种不同性质图形节点的图元。"),
            ID_CMD_GREP_CREATE_MODEL, L":/images/Module/Common/model.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opGRepCreateModelDefinition, L"opGRepCreateModelDefinition为空", L"GDMP", L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opGRepCreateModelDefinition));

    OwnerPtr<ICommandButtonDefinition> opHelpDefinition =
        ICommandButtonDefinition::Create(ID_CMD_GREP_HELP, GBMP_TR(L"帮助"), GBMP_TR(L"打开GDMP在线帮助网站"),
            ID_CMD_GREP_HELP, L":/images/Module/Common/Help.png");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opHelpDefinition, L"opHelpDefinition为空", L"GDMP", L"2024-03-30");
    opGrepGroup->AddButton(TransferOwnership(opHelpDefinition));

    ModuleUIUtils::Get()->SetupModuleUI(TransferOwnership(opGrepGroup), groupName);
    return nullptr;
}
#pragma endregion CmdGRepModuleEntry

